//
//  YBReceiveRedEnvelopeCell.m
//  yibeilive
//
//  Created by 南无本师释迦牟尼佛 on 2022/11/18.
//

#import "YBReceiveRedEnvelopeCell.h"

@implementation YBReceiveRedEnvelopeCell

// 初始化控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = [UIColor redColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 1;
        [self.container addSubview:_titleLabel];
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
    }
    return self;
}

// 根据 cellData 绘制 cell
- (void)fillWithData:(YBReceiveRedEnvelopeCellData *)data {
    [super fillWithData:data];
    
    NSString *title = [NSString stringWithFormat:@"%@抢到了%@的%@玫瑰",data.getHbuserName,data.sendHbUserName,data.count];
    NSString *str1 = @"抢到了";
    NSString *str2 = [NSString stringWithFormat:@"的%@玫瑰",data.count];
    
    NSRange range1 = [title rangeOfString:str1];
    NSRange range2 = [title rangeOfString:str2];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:title];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range1];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range2];
    self.titleLabel.attributedText = attributedString;
    
    [self setNeedsLayout];
}

// 设置控件坐标
- (void)layoutSubviews {
    [super layoutSubviews];
    self.container.mm_center();
    self.titleLabel.mm_fill();

    self.iconV.hidden = YES;
    self.nameLabel.hidden = YES;
    self.avatarView.hidden = YES;
    self.retryView.hidden = YES;
    [self.indicator stopAnimating];
}

@end
